package yjsonrpc

import (
	"fmt"
	jrpc "github.com/iloveswift/go-jsonrpc"
)

type Service struct {
	jsonRpc jrpc.ServerInterface
}

func (s *Service) Start(c interface{}) {
	s.jsonRpc.Register(c)
	s.jsonRpc.Start()
}

func NewService(conf Conf) (s *Service, e error) {
	rpc, err := jrpc.NewServer(conf.Type, conf.Host, conf.Port)
	if err != nil {
		e = err
		return
	}

	s = &Service{jsonRpc: rpc}
	fmt.Printf("监听:%s:%s:%s \r\n", conf.Type, conf.Host, conf.Port)
	return
}
